<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>OptionsPricing: DerivativePlots.py Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">OptionsPricing
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="dir_fb9351a6b940731fc8bdead6ec576523.html">input_output</a>      </li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">DerivativePlots.py</div>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">#!/usr/bin/python</span>
<a name="l00002"></a>00002 <span class="comment"># -*- coding: utf-8 -*-</span>
<a name="l00003"></a>00003 
<a name="l00004"></a>00004 <span class="keyword">from</span> __future__ <span class="keyword">import</span> with_statement
<a name="l00005"></a>00005 
<a name="l00006"></a>00006 <span class="keyword">from</span> pylab <span class="keyword">import</span> meshgrid, linspace
<a name="l00007"></a>00007 <span class="keyword">from</span> pylab <span class="keyword">import</span> xlabel, ylabel, title
<a name="l00008"></a>00008 <span class="keyword">from</span> numpy <span class="keyword">import</span> asarray, seterr
<a name="l00009"></a>00009 
<a name="l00010"></a>00010 <span class="keyword">import</span> matplotlib.pyplot <span class="keyword">as</span> plt
<a name="l00011"></a>00011 <span class="keyword">from</span> mpl_toolkits.mplot3d.axes3d <span class="keyword">import</span> Axes3D
<a name="l00012"></a>00012 
<a name="l00013"></a>00013 
<a name="l00014"></a><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html">00014</a> <span class="keyword">class </span><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html">DerivativePlots</a>(object):
<a name="l00015"></a>00015 
<a name="l00016"></a>00016     <span class="stringliteral">&quot;&quot;&quot; use to visualize results from pricing engine. &quot;&quot;&quot;</span>
<a name="l00017"></a>00017 
<a name="l00018"></a>00018     __slots__ = [
<a name="l00019"></a>00019         <span class="stringliteral">&#39;m_axis_leyend&#39;</span>,
<a name="l00020"></a>00020         <span class="stringliteral">&#39;m_curve_leyends&#39;</span>,
<a name="l00021"></a>00021         <span class="stringliteral">&#39;m_colors&#39;</span>,
<a name="l00022"></a>00022         <span class="stringliteral">&#39;m_exit_time&#39;</span>,
<a name="l00023"></a>00023         <span class="stringliteral">&#39;m_fig&#39;</span>,
<a name="l00024"></a>00024         <span class="stringliteral">&#39;m_xcoor&#39;</span>,
<a name="l00025"></a>00025         <span class="stringliteral">&#39;m_yvals&#39;</span>,
<a name="l00026"></a>00026         <span class="stringliteral">&#39;m_vol&#39;</span>,
<a name="l00027"></a>00027         <span class="stringliteral">&#39;m_vol_analy&#39;</span>,
<a name="l00028"></a>00028         <span class="stringliteral">&#39;m_ptitle&#39;</span>,
<a name="l00029"></a>00029         <span class="stringliteral">&#39;m_posi&#39;</span>,
<a name="l00030"></a>00030         <span class="stringliteral">&#39;m_line_style&#39;</span>,
<a name="l00031"></a>00031         <span class="stringliteral">&#39;m_yhist&#39;</span>,
<a name="l00032"></a>00032         <span class="stringliteral">&#39;m_time_elapse&#39;</span>,
<a name="l00033"></a>00033         ]
<a name="l00034"></a>00034 
<a name="l00035"></a><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a65db2a516b950212bd8bef9c1ae3bd81">00035</a>     <span class="keyword">def </span><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a65db2a516b950212bd8bef9c1ae3bd81">__init__</a>(self):
<a name="l00036"></a>00036         <span class="stringliteral">&quot;&quot;&quot; initilialize all the variable neede for plotting. &quot;&quot;&quot;</span>
<a name="l00037"></a>00037 
<a name="l00038"></a>00038         (self.m_xcoor, self.m_yvals) = (<span class="keywordtype">None</span>, <span class="keywordtype">None</span>)
<a name="l00039"></a>00039         (self.m_vol, self.m_vol_analy) = (<span class="keywordtype">None</span>, <span class="keywordtype">None</span>)
<a name="l00040"></a>00040 
<a name="l00041"></a>00041         (self.m_time_elapse, self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a6dd1f5ca84dda68593bea93067a65440">m_exit_time</a>) = (<span class="keywordtype">None</span>, -1.0)
<a name="l00042"></a>00042         (self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a7c484044a86dd001673ccfca578912a3">m_ptitle</a>, self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a429de24154e6f0526e8b2910dd6dc2b1">m_line_style</a>, self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#aeb3005e00aa90d544b800577f9feb1e8">m_curve_leyends</a>) = \
<a name="l00043"></a>00043             (<span class="keywordtype">None</span>, <span class="keywordtype">None</span>, <span class="keywordtype">None</span>)
<a name="l00044"></a>00044 
<a name="l00045"></a>00045         self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a5b2d575f72d7cc396349d43fff58673c">m_yhist</a> = <span class="keywordtype">None</span>
<a name="l00046"></a>00046         self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#ae09ea8f62fcf8c0c52b44c18eb57bae1">m_posi</a> = 1
<a name="l00047"></a>00047         self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a27bad2b3a8eeac110b5be678693999b1">m_axis_leyend</a> = {}
<a name="l00048"></a>00048         self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a61ad3852f19ca122b7ca1776cb4de837">m_colors</a> = [<span class="stringliteral">&#39;blue&#39;</span>, <span class="stringliteral">&#39;green&#39;</span>, <span class="stringliteral">&#39;red&#39;</span>, <span class="stringliteral">&#39;yellow&#39;</span>]
<a name="l00049"></a>00049 
<a name="l00050"></a>00050         <span class="comment"># Set error handling to known state.</span>
<a name="l00051"></a>00051 
<a name="l00052"></a>00052         seterr(all=<span class="stringliteral">&#39;ignore&#39;</span>)
<a name="l00053"></a>00053         self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a8a923febc9381180b7b991ae42d52ea6">m_fig</a> = plt.figure(figsize=(11.5, 5.0))
<a name="l00054"></a>00054 
<a name="l00055"></a><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#ae531c7383b99fac3070714dd33fcdbaf">00055</a>     <span class="keyword">def </span><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#ae531c7383b99fac3070714dd33fcdbaf">set_curves</a>(self, xcoor, ycoors):
<a name="l00056"></a>00056         <span class="stringliteral">&quot;&quot;&quot; ordinate and possible several absise. &quot;&quot;&quot;</span>
<a name="l00057"></a>00057 
<a name="l00058"></a>00058         (self.m_xcoor, self.m_yvals) = (xcoor, ycoors)
<a name="l00059"></a>00059 
<a name="l00060"></a><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a52a12f24d9089a8c725f4ace50c7ffd9">00060</a>     <span class="keyword">def </span><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a52a12f24d9089a8c725f4ace50c7ffd9">set_history</a>(self, xcoor, yhist, time_elapse):
<a name="l00061"></a>00061         <span class="stringliteral">&quot;&quot;&quot; use to plot time stepper history. &quot;&quot;&quot;</span>
<a name="l00062"></a>00062 
<a name="l00063"></a>00063         (self.m_xcoor, self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a5b2d575f72d7cc396349d43fff58673c">m_yhist</a>, self.m_time_elapse) = (xcoor, yhist,
<a name="l00064"></a>00064                 time_elapse)
<a name="l00065"></a>00065 
<a name="l00066"></a><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a148c569e9ffec2c090a11a3d5b5d733b">00066</a>     <span class="keyword">def </span><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a148c569e9ffec2c090a11a3d5b5d733b">set_vol_surface</a>(self, xcoor, y_coor, vol, vol_analy=None):
<a name="l00067"></a>00067         <span class="stringliteral">&quot;&quot;&quot; 3D plot. &quot;&quot;&quot;</span>
<a name="l00068"></a>00068 
<a name="l00069"></a>00069         (self.m_xcoor, self.m_yvals, self.m_vol, self.m_vol_analy) = (xcoor,
<a name="l00070"></a>00070                                                       y_coor, vol, vol_analy)
<a name="l00071"></a>00071 
<a name="l00072"></a><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a6f5323f7b89f2cb2c7327fdeeb9876eb">00072</a>     <span class="keyword">def </span><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a6f5323f7b89f2cb2c7327fdeeb9876eb">set_curve_leyends</a>(self, names):
<a name="l00073"></a>00073         <span class="stringliteral">&quot;&quot;&quot; give some meaningfull description of the curve. &quot;&quot;&quot;</span>
<a name="l00074"></a>00074 
<a name="l00075"></a>00075         self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#aeb3005e00aa90d544b800577f9feb1e8">m_curve_leyends</a> = names
<a name="l00076"></a>00076 
<a name="l00077"></a><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a4e2d8859882d44bb9588c49b912a8d57">00077</a>     <span class="keyword">def </span><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a4e2d8859882d44bb9588c49b912a8d57">set_leyend_posi</a>(self, posi):
<a name="l00078"></a>00078         <span class="stringliteral">&quot;&quot;&quot; left, right, bot, top. &quot;&quot;&quot;</span>
<a name="l00079"></a>00079 
<a name="l00080"></a>00080         self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#ae09ea8f62fcf8c0c52b44c18eb57bae1">m_posi</a> = posi
<a name="l00081"></a>00081 
<a name="l00082"></a><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a8c5ae0988e2d04888878b6a4413c03fb">00082</a>     <span class="keyword">def </span><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a8c5ae0988e2d04888878b6a4413c03fb">set_axis_leyend</a>(self, axis_leyend):
<a name="l00083"></a>00083         <span class="stringliteral">&quot;&quot;&quot; describe the plotting. &quot;&quot;&quot;</span>
<a name="l00084"></a>00084 
<a name="l00085"></a>00085         self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a27bad2b3a8eeac110b5be678693999b1">m_axis_leyend</a> = axis_leyend
<a name="l00086"></a>00086 
<a name="l00087"></a><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a3d27ade669bcf3109c4acae420eabc78">00087</a>     <span class="keyword">def </span><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a3d27ade669bcf3109c4acae420eabc78">set_title</a>(self, ptitle):
<a name="l00088"></a>00088         <span class="stringliteral">&quot;&quot;&quot; what is it you are plotting. &quot;&quot;&quot;</span>
<a name="l00089"></a>00089 
<a name="l00090"></a>00090         self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a7c484044a86dd001673ccfca578912a3">m_ptitle</a> = ptitle
<a name="l00091"></a>00091 
<a name="l00092"></a><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a8210d93273f451992698e49b1f43bae0">00092</a>     <span class="keyword">def </span><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a8210d93273f451992698e49b1f43bae0">set_colors</a>(self, colors):
<a name="l00093"></a>00093         <span class="stringliteral">&quot;&quot;&quot; look at matplot for valid colors. &quot;&quot;&quot;</span>
<a name="l00094"></a>00094 
<a name="l00095"></a>00095         self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a61ad3852f19ca122b7ca1776cb4de837">m_colors</a> = colors
<a name="l00096"></a>00096 
<a name="l00097"></a><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a8722db7828bb8fba081d19f3f059e6e6">00097</a>     <span class="keyword">def </span><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a8722db7828bb8fba081d19f3f059e6e6">set_line_style</a>(self, line_style):
<a name="l00098"></a>00098         <span class="stringliteral">&quot;&quot;&quot; look at matplot for valid colors. &quot;&quot;&quot;</span>
<a name="l00099"></a>00099 
<a name="l00100"></a>00100         self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a429de24154e6f0526e8b2910dd6dc2b1">m_line_style</a> = line_style
<a name="l00101"></a>00101 
<a name="l00102"></a><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#acd037766b7f41263369b0a062162f491">00102</a>     <span class="keyword">def </span><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#acd037766b7f41263369b0a062162f491">set_exit_time</a>(self, exp_time):
<a name="l00103"></a>00103         <span class="stringliteral">&quot;&quot;&quot; not implemented yet. &quot;&quot;&quot;</span>
<a name="l00104"></a>00104 
<a name="l00105"></a>00105         self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a6dd1f5ca84dda68593bea93067a65440">m_exit_time</a> = float(exp_time)
<a name="l00106"></a>00106 
<a name="l00107"></a><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a010e7939ec0c5eeaf2a65f29a3c1658f">00107</a>     <span class="keyword">def </span><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a010e7939ec0c5eeaf2a65f29a3c1658f">plot</a>(self, axis=None):
<a name="l00108"></a>00108         <span class="stringliteral">&quot;&quot;&quot; plot 2 or 3 D. &quot;&quot;&quot;</span>
<a name="l00109"></a>00109 
<a name="l00110"></a>00110         <span class="keywordflow">if</span> axis <span class="keywordflow">is</span> <span class="keywordtype">None</span>:
<a name="l00111"></a>00111             axis = self.m_fig.gca()
<a name="l00112"></a>00112 
<a name="l00113"></a>00113         handle = []
<a name="l00114"></a>00114         <span class="keywordflow">for</span> (i, y_coor) <span class="keywordflow">in</span> enumerate(self.m_yvals):
<a name="l00115"></a>00115             (hand, ) = axis.plot(self.m_xcoor, y_coor, <span class="stringliteral">&#39;-&#39;</span>,
<a name="l00116"></a>00116                                  color=self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a61ad3852f19ca122b7ca1776cb4de837">m_colors</a>[i])
<a name="l00117"></a>00117             handle.append(hand)
<a name="l00118"></a>00118 
<a name="l00119"></a>00119         <span class="keywordflow">if</span> 0 &lt; len(self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#aeb3005e00aa90d544b800577f9feb1e8">m_curve_leyends</a>):
<a name="l00120"></a>00120             axis.legend(handle, self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#aeb3005e00aa90d544b800577f9feb1e8">m_curve_leyends</a>, self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#ae09ea8f62fcf8c0c52b44c18eb57bae1">m_posi</a>)
<a name="l00121"></a>00121 
<a name="l00122"></a>00122         self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#aea58378c554df8c67f02534530341d0b">_add_axis_leyends</a>()
<a name="l00123"></a>00123 
<a name="l00124"></a>00124         plt.show()
<a name="l00125"></a>00125 
<a name="l00126"></a><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a15df11c160e3d1b3496a02b935ad4195">00126</a>     <span class="keyword">def </span><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a15df11c160e3d1b3496a02b935ad4195">plot_history</a>(self):
<a name="l00127"></a>00127         <span class="stringliteral">&quot;&quot;&quot; use this function to plot pde history. &quot;&quot;&quot;</span>
<a name="l00128"></a>00128 
<a name="l00129"></a>00129         (x_grid, t_grid) = meshgrid(self.m_xcoor, linspace(0, \
<a name="l00130"></a>00130                                     self.m_time_elapse, self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a5b2d575f72d7cc396349d43fff58673c">m_yhist</a>.shape[0]))
<a name="l00131"></a>00131         <span class="keyword">assert</span> x_grid.shape == self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a5b2d575f72d7cc396349d43fff58673c">m_yhist</a>.shape
<a name="l00132"></a>00132 
<a name="l00133"></a>00133         rect = self.m_fig.add_subplot(1, 2, 1).get_position()
<a name="l00134"></a>00134         ax1 = Axes3D(self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a8a923febc9381180b7b991ae42d52ea6">m_fig</a>, rect)
<a name="l00135"></a>00135         ax1.plot_surface(x_grid, t_grid, asarray(self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a5b2d575f72d7cc396349d43fff58673c">m_yhist</a>, <span class="stringliteral">&#39;float16&#39;</span>))
<a name="l00136"></a>00136         <span class="comment">#self._add_axis_leyends()</span>
<a name="l00137"></a>00137 
<a name="l00138"></a>00138         axis2 = self.m_fig.add_subplot(1, 2, 2)
<a name="l00139"></a>00139         self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a010e7939ec0c5eeaf2a65f29a3c1658f">plot</a>(axis2)
<a name="l00140"></a>00140 
<a name="l00141"></a><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#abdea807734d395b51dac55a81cc97c5f">00141</a>     <span class="keyword">def </span><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#abdea807734d395b51dac55a81cc97c5f">plot_vol_surfaces</a>(self):
<a name="l00142"></a>00142         <span class="stringliteral">&quot;&quot;&quot; self describing name. &quot;&quot;&quot;</span>
<a name="l00143"></a>00143 
<a name="l00144"></a>00144         <span class="keyword">assert</span> self.m_xcoor <span class="keywordflow">is</span> <span class="keywordflow">not</span> <span class="keywordtype">None</span>
<a name="l00145"></a>00145         <span class="keyword">assert</span> self.m_yvals <span class="keywordflow">is</span> <span class="keywordflow">not</span> <span class="keywordtype">None</span>
<a name="l00146"></a>00146         <span class="keyword">assert</span> self.m_vol <span class="keywordflow">is</span> <span class="keywordflow">not</span> <span class="keywordtype">None</span>
<a name="l00147"></a>00147 
<a name="l00148"></a>00148         <span class="comment"># ---- First subplot</span>
<a name="l00149"></a>00149 
<a name="l00150"></a>00150         <span class="keywordflow">if</span> self.m_vol_analy <span class="keywordflow">is</span> <span class="keywordflow">not</span> <span class="keywordtype">None</span>:
<a name="l00151"></a>00151             rect = self.m_fig.add_subplot(1, 2, 1).get_position()
<a name="l00152"></a>00152             axis = Axes3D(self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a8a923febc9381180b7b991ae42d52ea6">m_fig</a>, rect)
<a name="l00153"></a>00153         <span class="keywordflow">else</span>:
<a name="l00154"></a>00154             axis = Axes3D(self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a8a923febc9381180b7b991ae42d52ea6">m_fig</a>)
<a name="l00155"></a>00155 
<a name="l00156"></a>00156         axis.plot_surface(self.m_xcoor, self.m_yvals, asarray(self.m_vol,
<a name="l00157"></a>00157                         <span class="stringliteral">&#39;float16&#39;</span>), rstride=1, cstride=1,
<a name="l00158"></a>00158                         linewidth=0, antialiased=<span class="keyword">False</span>)
<a name="l00159"></a>00159 
<a name="l00160"></a>00160 
<a name="l00161"></a>00161         axis.set_xlabel(<span class="stringliteral">&#39;Stoke Price&#39;</span>)
<a name="l00162"></a>00162         axis.set_ylabel(<span class="stringliteral">&#39;Time to Expiration&#39;</span>)
<a name="l00163"></a>00163         axis.set_zlabel(<span class="stringliteral">&#39;Calibrated Volatility&#39;</span>)
<a name="l00164"></a>00164 
<a name="l00165"></a>00165         <span class="comment"># ---- Second subplot</span>
<a name="l00166"></a>00166 
<a name="l00167"></a>00167         <span class="keywordflow">if</span> self.m_vol_analy <span class="keywordflow">is</span> <span class="keywordflow">not</span> <span class="keywordtype">None</span>:
<a name="l00168"></a>00168             rect = self.m_fig.add_subplot(1, 2, 2).get_position()
<a name="l00169"></a>00169             axis2 = Axes3D(self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a8a923febc9381180b7b991ae42d52ea6">m_fig</a>, rect)
<a name="l00170"></a>00170 
<a name="l00171"></a>00171             axis2.plot_surface(self.m_xcoor, self.m_yvals, asarray(
<a name="l00172"></a>00172                 self.m_vol_analy, <span class="stringliteral">&#39;float16&#39;</span>), rstride=1, cstride=1,
<a name="l00173"></a>00173                 linewidth=0, antialiased=<span class="keyword">False</span>)
<a name="l00174"></a>00174 
<a name="l00175"></a>00175             axis2.set_xlabel(<span class="stringliteral">&#39;Stoke Price&#39;</span>)
<a name="l00176"></a>00176             axis2.set_ylabel(<span class="stringliteral">&#39;Time to Expiration&#39;</span>)
<a name="l00177"></a>00177             axis2.set_zlabel(<span class="stringliteral">&#39;Analytical Volatility&#39;</span>)
<a name="l00178"></a>00178 
<a name="l00179"></a>00179         plt.show()
<a name="l00180"></a>00180 
<a name="l00181"></a><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a8512ad8b0fb6f7c55e9f739e956338e3">00181</a>     <span class="keyword">def </span><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a8512ad8b0fb6f7c55e9f739e956338e3">plot_greeks</a>(self):
<a name="l00182"></a>00182         <span class="stringliteral">&quot;&quot;&quot; greeks. &quot;&quot;&quot;</span>
<a name="l00183"></a>00183 
<a name="l00184"></a>00184         ax1 = self.m_fig.add_subplot(1, 2, 1)
<a name="l00185"></a>00185         ax1.plot(self.m_xcoor, self.m_yvals[0])
<a name="l00186"></a>00186         self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#aea58378c554df8c67f02534530341d0b">_add_axis_leyends</a>()
<a name="l00187"></a>00187 
<a name="l00188"></a>00188         axis2 = self.m_fig.add_subplot(1, 2, 2)
<a name="l00189"></a>00189         axis2.plot(self.m_xcoor, self.m_yvals[1])
<a name="l00190"></a>00190         axis2.plot(self.m_xcoor, self.m_yvals[2])
<a name="l00191"></a>00191         self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a27bad2b3a8eeac110b5be678693999b1">m_axis_leyend</a>[<span class="stringliteral">&#39;y&#39;</span>] = <span class="stringliteral">&#39;Delta / Gamma&#39;</span>
<a name="l00192"></a>00192         self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#aea58378c554df8c67f02534530341d0b">_add_axis_leyends</a>()
<a name="l00193"></a>00193 
<a name="l00194"></a>00194         self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a867e6778e6047dfd0b4862238cd19bb9">exit_if_requested</a>()
<a name="l00195"></a>00195         plt.show()
<a name="l00196"></a>00196 
<a name="l00197"></a><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a867e6778e6047dfd0b4862238cd19bb9">00197</a>     <span class="keyword">def </span><a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a867e6778e6047dfd0b4862238cd19bb9">exit_if_requested</a>(self):
<a name="l00198"></a>00198         <span class="stringliteral">&quot;&quot;&quot; this method is not working yet. &quot;&quot;&quot;</span>
<a name="l00199"></a>00199 
<a name="l00200"></a>00200         <span class="keywordflow">if</span> self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a6dd1f5ca84dda68593bea93067a65440">m_exit_time</a> &gt; 0:
<a name="l00201"></a>00201             <span class="keywordflow">pass</span>
<a name="l00202"></a>00202 
<a name="l00203"></a>00203         <span class="comment"># look at : http://matplotlib.sourceforge.net/examples/</span>
<a name="l00204"></a>00204         <span class="comment">#                 animation/animate_decay_tk_blit.py</span>
<a name="l00205"></a>00205         <span class="comment">#&quot; it is not working &quot;</span>
<a name="l00206"></a>00206         <span class="comment">#time.wait(self.m_exit_time)</span>
<a name="l00207"></a>00207         <span class="comment">#sys.exit()</span>
<a name="l00208"></a>00208 
<a name="l00209"></a>00209     <span class="keyword">def </span>_add_axis_leyends(self):
<a name="l00210"></a>00210         <span class="stringliteral">&quot;&quot;&quot; is there any thing to put on the leyend. &quot;&quot;&quot;</span>
<a name="l00211"></a>00211 
<a name="l00212"></a>00212         <span class="keywordflow">if</span> self.m_axis_leyend.has_key(<span class="stringliteral">&#39;x&#39;</span>):
<a name="l00213"></a>00213             xlabel(self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a27bad2b3a8eeac110b5be678693999b1">m_axis_leyend</a>[<span class="stringliteral">&#39;x&#39;</span>])
<a name="l00214"></a>00214 
<a name="l00215"></a>00215         <span class="keywordflow">if</span> self.m_axis_leyend.has_key(<span class="stringliteral">&#39;y&#39;</span>):
<a name="l00216"></a>00216             ylabel(self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a27bad2b3a8eeac110b5be678693999b1">m_axis_leyend</a>[<span class="stringliteral">&#39;y&#39;</span>])
<a name="l00217"></a>00217 
<a name="l00218"></a>00218         <span class="keywordflow">if</span> self.m_axis_leyend.has_key(<span class="stringliteral">&#39;z&#39;</span>):
<a name="l00219"></a>00219             ylabel(self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a27bad2b3a8eeac110b5be678693999b1">m_axis_leyend</a>[<span class="stringliteral">&#39;z&#39;</span>])
<a name="l00220"></a>00220 
<a name="l00221"></a>00221         <span class="keywordflow">if</span> self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a7c484044a86dd001673ccfca578912a3">m_ptitle</a> <span class="keywordflow">is</span> <span class="keywordflow">not</span> <span class="keywordtype">None</span>:
<a name="l00222"></a>00222             title(self.<a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html#a7c484044a86dd001673ccfca578912a3">m_ptitle</a>)
<a name="l00223"></a>00223 
<a name="l00224"></a>00224 
<a name="l00225"></a>00225 <span class="keywordflow">if</span> __name__ == <span class="stringliteral">&#39;__main__&#39;</span>:
<a name="l00226"></a>00226     <span class="keyword">from</span> numpy <span class="keyword">import</span> ones, exp, linspace
<a name="l00227"></a>00227 
<a name="l00228"></a>00228     deri_plot = <a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html">DerivativePlots</a>()
<a name="l00229"></a>00229 
<a name="l00230"></a>00230     (plot_curves, plot_surface) = (<span class="keyword">False</span>, <span class="keyword">True</span>)
<a name="l00231"></a>00231 
<a name="l00232"></a>00232     <span class="keywordflow">if</span> plot_curves:
<a name="l00233"></a>00233         x_coor = asarray(linspace(0, 1, 100))
<a name="l00234"></a>00234         y2 = 2 * ones(x_coor.shape)
<a name="l00235"></a>00235         y1 = exp(x_coor)
<a name="l00236"></a>00236 
<a name="l00237"></a>00237         deri_plot.set_curves(x_coor, [y1, y2])
<a name="l00238"></a>00238         deri_plot.set_curve_leyends([<span class="stringliteral">&#39;one&#39;</span>, <span class="stringliteral">&#39;two&#39;</span>])
<a name="l00239"></a>00239         deri_plot.set_axis_leyend({<span class="stringliteral">&#39;x&#39;</span>: <span class="stringliteral">&#39;price&#39;</span>})
<a name="l00240"></a>00240         deri_plot.set_leyend_posi(2)
<a name="l00241"></a>00241         deri_plot.plot()
<a name="l00242"></a>00242 
<a name="l00243"></a>00243     <span class="keywordflow">if</span> plot_surface:
<a name="l00244"></a>00244         x_coor = asarray(linspace(-2, 2, 50))
<a name="l00245"></a>00245         (X, Y) = meshgrid(x_coor, x_coor)
<a name="l00246"></a>00246         Z = exp(X ** 2 + Y ** 2)
<a name="l00247"></a>00247 
<a name="l00248"></a>00248         deri_plot.set_vol_surface(X, Y, Z, Z)
<a name="l00249"></a>00249         deri_plot.plot_vol_surfaces()
<a name="l00250"></a>00250 
</pre></div></div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Functions</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Thu Dec 22 2011 05:17:53 for OptionsPricing by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.5.1
</small></address>

</body>
</html>
